export async function load(ui) {
    // 遍历json
    var controls = new Map()
    Object.keys(ui).forEach(async key => {
        var control = await createUI(key, ui[key])
        controls.set(ui[key].id, control)
    })
}

async function createUI(key, obj) {
    switch (key) {
        case "border":
            return await CreateBorder(obj)
        case "grid":
            return await CreateGrid(obj)
        case "stackPanel":
            return await CreateStackPanel(obj)
    }
}

async function CreateBorder(obj) {
    var Border = wpf.System.Windows.Controls.Border
    var Thickness = wpf.System.Windows.Thickness
    var BrushConverter = wpf.System.Windows.Media.BrushConverter
    
    var brushConverter = new BrushConverter()

    var border = new Border()
    var paddings = obj["padding"].split(' ')
    border.Padding = new Thickness(parseInt(paddings[0]), parseInt(paddings[1]), parseInt(paddings[2]), parseInt(paddings[3]))
    border.MinWidth = obj["minWidth"]
    border.MinHeight = obj["minHeight"]
    border.Background = brushConverter.ConvertFromString(obj["background"])
    border.BorderBrush = brushConverter.ConvertFromString(obj["borderbrush"])

    return {
        "obj": obj,
        "control": border
    }
}

async function CreateGrid(obj) {

}

async function CreateStackPanel(obj) {

}